﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/MasterPage.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<EM.Components.Entities.EM_Leads>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Index
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
    $(function () {
        var deleteLinkObj;
        $('.delete-link').click(function (event) {
            event.preventDefault();
            deleteLinkObj = $(this);
            if (confirm("R U Sure?")) {
                $.post(this.href, function (data) {
                    if (data == '<%:Boolean.TrueString %>') {
                   deleteLinkObj.closest("tr").remove();
                    } 
                });
            };
        });

        <%-- The follwing implement the same thing except it defines dialog style --%>
        //        $('.delete-link').click(function () {
        //            deleteLinkObj = $(this);
        //            $('#delete-dialog').dialog('open');
        //            return false;
        //        });

        //        $('#delete-dialog').dialog({
        //            autoOpen: false, width: 400, resizable: false, modal: true,
        //            buttons: {
        //                "Continue": function () {
        //                    $.post(deleteLinkObj[0].href, function (data) {
        //                        if (data == '<%= Boolean.TrueString %>') {
        //                            deleteLinkObj.closest("tr").hide('fast');
        //                        }
        //                        else {
        //                            alert("error");
        //                        }
        //                    });
        //                    $(this).dialog("close");
        //                },
        //                "Cancel": function () {
        //                    $(this).dialog("close");
        //                }
        //            }
        //        });
    });
</script>
    <h2>Index</h2>

    <table>
        <tr>
            <th></th>
            <th>
                LeadID
            </th>
            <th>
                FirstName
            </th>
            <th>
                LastName
            </th>
            <th>
                EmailAddress
            </th>
            <th>
                IsValid
            </th>
            <th>
                Unsubscribed
            </th>
        </tr>

    <% foreach (var item in Model) { %>
        <tr>
            <td>
                <%: Html.ActionLink("Edit", "Edit", new { id=item.LeadID }) %> |
                <%: Html.ActionLink("Delete", "Delete", new { id = item.LeadID }, new { @class="delete-link"})%>
            </td>
            <td>
                <%: item.LeadID %>
            </td>
            <td>
                <%: item.FirstName %>
            </td>
            <td>
                <%: item.LastName %>
            </td>
            <td>
                <%: item.EmailAddress %>
            </td>
            <td>
                <%: item.IsValid %>
            </td>
            <td>
                <%: item.Unsubscribed %>
            </td>
        </tr>
    
    <% } %>

    </table>

    <p>
        <%: Html.ActionLink("Create New", "Create") %>
    </p>
<%--    <div id="delete-dialog" title="Confirmation">
    <p>Are you sure?
    </p>
    </div>--%>

</asp:Content>

